import { Entity } from "./Entity";
import { IComponent } from "./IComponent";

/**
 * 匹配器
 */
export class Matcher {

    matcher: MatcherAllOf | MatcherAnyOf | MatcherNoneOf | null = null;

    anyOf: MatcherAnyOf | null = null;

    noneOf: MatcherNoneOf | null = null;

    entitys: Set<Entity>;

    constructor(allOrAny: MatcherAllOf | MatcherAnyOf, anyOf: MatcherAnyOf, none: MatcherNoneOf) {
        this.matcher = allOrAny;
        this.anyOf = anyOf;
        this.noneOf = none;
        this.entitys = new Set<Entity>();
    }

    destroy(): void {
        this.matcher = null;
        this.anyOf = null;
        this.noneOf = null;
    }
}



export abstract class BaseMatcher {

    types: Array<new () => IComponent>;

    constructor(types: Array<new () => IComponent>) {
        this.types = types;
    }
}


/**
 * 必须包含所有类型
 */
export class MatcherAllOf extends BaseMatcher {
    constructor(types: Array<new () => IComponent>) {
        super(types);
    }
}


/**
 * 必须包含任意一个类型
 */
export class MatcherAnyOf extends BaseMatcher {
    constructor(types: Array<new () => IComponent>) {
        super(types);
    }
}

/**
 * 不包含所有类型
 */
export class MatcherNoneOf extends BaseMatcher {
    constructor(types: Array<new () => IComponent>) {
        super(types);
    }
}